package com.grace.service;

import com.grace.dao.StudentDao;
import com.grace.dao.StudentDaoImpl;
import com.grace.entity.Student;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    StudentDao studentDao = new StudentDaoImpl();

    @Override
    public Student selectStudentById(Long id) {
        return studentDao.selectStudent(id);
    }

    @Override
    public Student selectStudentBySnoAndPwd(String sno, String pwd) {
        return studentDao.selectStudent(sno, pwd);
    }

    @Override
    public void regist(Student student) {
        studentDao.insert(student);
    }

    @Override
    public List<Student> getPageStudents(int pageNo, int pageSize) {
        return studentDao.getPageStudents(pageNo, pageSize);
    }

    @Override
    public long getCount() {
        return studentDao.getCount();
    }

    @Override
    public void delSelectedStudent(String[] ids) {
        if (ids != null && ids.length > 0) {
            //1.遍历数组
            for (String id : ids) {
                //2.调用dao删除
                Student student = studentDao.selectStudent(Long.parseLong(id));
                studentDao.deleteStudent(student);
            }
        }

    }

    @Override
    public void updateStudent(Student student) {
        studentDao.update(student);
    }
}
